package com.simple.datax.bo.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.simple.datax.bo.IDataxSendChannelBO;
import com.simple.datax.dao.IDataxSendChannelDAO;
import com.simple.datax.vo.DataxSendChannelVO;
import com.simple.util.common.DateUtil;
import com.simple.util.object.PageInfoBean;

@Service("dataxSendChannelBO")
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
public class DataxSendChannelBOImpl implements IDataxSendChannelBO {

	@Autowired
	private IDataxSendChannelDAO dataxSendChannelDAO;
	
	@Override
	public DataxSendChannelVO findById(Integer fiId) {
		return dataxSendChannelDAO.findById(fiId);
	}

	@Override
	public List<DataxSendChannelVO> findAll() {
		return dataxSendChannelDAO.findAll();
	}

	@Override
	public List<DataxSendChannelVO> findDataxSendChannelVOByPage(
			PageInfoBean pageInfoBean, String fiId, String fcCommunType,
			String fcMsgFormateId, String fcMsgType) {
		return dataxSendChannelDAO.findDataxSendChannelVOByPage(pageInfoBean, fiId, fcCommunType, fcMsgFormateId, fcMsgType);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
	public void add(DataxSendChannelVO dataxSendChannelVO) {
		
		dataxSendChannelVO.setFdTime(DateUtil.getNowDate());
		dataxSendChannelDAO.saveOrUpdate(dataxSendChannelVO);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false,rollbackFor={Exception.class})
	public void edit(DataxSendChannelVO dataxSendChannelVO) {
		DataxSendChannelVO dscv = dataxSendChannelDAO.findById(dataxSendChannelVO.getFiId());
		
		dscv.setFcChannelDesc(dataxSendChannelVO.getFcChannelDesc());
		dscv.setFcCommunParam(dataxSendChannelVO.getFcCommunParam());
		dscv.setFcCommunType(dataxSendChannelVO.getFcCommunType());
		dscv.setFcMsgCharset(dataxSendChannelVO.getFcMsgCharset());
		dscv.setFcMsgFormateId(dataxSendChannelVO.getFcMsgFormateId());
		dscv.setFcMsgType(dataxSendChannelVO.getFcMsgType());
		dscv.setFiFlag(dataxSendChannelVO.getFiFlag());
		
		dataxSendChannelVO.setFdTime(DateUtil.getNowDate());
		dataxSendChannelDAO.saveOrUpdate(dscv);
	}

	@Override
	public Integer generateId() {
		return dataxSendChannelDAO.generateId();
	}

	@Override
	public Map<String, String> findSysSendIdMap() {
		 List<DataxSendChannelVO> dataxSendChannelVOList = dataxSendChannelDAO.findAll();
		 final Map<String ,String> map = new LinkedHashMap<String ,String>();
		 for(final DataxSendChannelVO dataxSendChannelVO: dataxSendChannelVOList){
			 map.put(String.valueOf(dataxSendChannelVO.getFiId()), dataxSendChannelVO.getFcChannelDesc());
		 }
		 return map;
	}

	@Override
	public List<DataxSendChannelVO> getDataxSendChannelVOByPage(
			PageInfoBean pageInfoBean, String fcChannelDesc) {
		return dataxSendChannelDAO.getDataxSendChannelVOByPage(pageInfoBean, fcChannelDesc);
	}
}